const path = require('path')

function resolve(dir) {
    return path.join(__dirname, dir)
}

function publicPath() {
    return process.env.NODE_ENV === 'production' ? '././' : '/'
}

module.exports = {
    publicPath: publicPath(),
    configureWebpack: {
        resolve: {
            alias: {
                '@': resolve('src')
            }
        }
    },
    lintOnSave: false,
    devServer: {
        host: "0.0.0.0",
        port: 8081,
        hot: true,
        https: false,
        proxy: {
            '/api': {  // 修改代理前缀为更通用的/api
                target: 'http://localhost:8080', // 去掉末尾的/shared_power_bank_system
                changeOrigin: true,
                secure: false,
                pathRewrite: {
                    '^/api': '/shared_power_bank_system' // 将/api重写为/shared_power_bank_system
                }
            }
        }
    },
    chainWebpack(config) {
        config.module
            .rule('svg')
            .exclude.add(resolve('src/icons'))
            .end()
        config.module
            .rule('icons')
            .test(/\.svg$/)
            .include.add(resolve('src/icons'))
            .end()
            .use('svg-sprite-loader')
            .loader('svg-sprite-loader')
            .options({
                symbolId: 'icon-[name]'
            })
            .end()
    }
}